//
//  RHContactUsVC.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2023/10/31.
//

#import "RHContactUsVC.h"
#import "RHContactUsCell.h"
#import "JXMapNavigationView.h"

@interface RHContactUsVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic ,strong) UITableView *tableView;

@property (nonatomic ,strong) UIView *customNav;

@property (nonatomic ,strong) NSArray *dataArr;

@property (nonatomic, strong)JXMapNavigationView * mapNavigationView;
@end

@implementation RHContactUsVC
- (JXMapNavigationView *)mapNavigationView{
    if (_mapNavigationView == nil) {
        _mapNavigationView = [[JXMapNavigationView alloc]init];
    }
    return _mapNavigationView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"联系我们".rh_localized;
    self.view.backgroundColor = CFTabViewBgColor;
    [self setupUI];
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

- (void)setupUI{
    self.dataArr = @[@{CellTitle:@"公司名称".rh_localized,CellContent:@"RuiHe Technology (Shenzhen) Co., Ltd"},
                     @{CellTitle:@"公司电话".rh_localized,CellContent:@"0755-8845036"},
                     @{CellTitle:@"售后电话".rh_localized,CellContent:@"0755-12478415"},
                     @{CellTitle:@"公司邮箱".rh_localized,CellContent:@"ruihepower@163.com"},
                     @{CellTitle:@"公司网址".rh_localized,CellContent:@"www.ruihepower.com"},
                     @{CellTitle:@"公司地址".rh_localized,CellContent:@"--".rh_localized}];
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    [_tableView setBackgroundColor:UIColor.clearColor];
    [_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [_tableView setDelegate:self];
    [_tableView setDataSource:self];
    [_tableView registerClass:[RHContactUsCell class] forCellReuseIdentifier:@"RHContactUsCell"];
    _tableView.tableHeaderView = [self headerView];
    _tableView.tableFooterView = [self footBgView];
    [self.view addSubview:_tableView];
    if (@available(iOS 11.0, *)) {
        _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }

    if (@available(iOS 15.0, *)) {
        _tableView.sectionHeaderTopPadding = 0;
    }

    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(0, 0, 0, 0));
    }];

}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    RHContactUsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RHContactUsCell"];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    cell.dic = self.dataArr[indexPath.row];
    if(indexPath.row == 1|| indexPath.row == 2){
        cell.contentLab.userInteractionEnabled = YES;
        cell.contentLab.textColor = kCOLOR_HEX(@"56C271");
    }else{
        cell.contentLab.userInteractionEnabled = NO;
        cell.contentLab.textColor = kCOLOR_HEX(@"3F4443");
    }
    
    return cell;
}


- (UIView *)headerView{

    UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kUI_WINDOW_W, kUI_WINDOW_W*0.46)];
    UIView *bgView = kView;
    bgView.backgroundColor = UIColor.whiteColor;
    bgView.layer.cornerRadius = 8;
    bgView.layer.masksToBounds = YES;
    [header addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(0, 15, 0, 15));
    }];
    
    UIImageView *mapImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mine_map"]];
    [bgView addSubview:mapImg];
    
    [mapImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(15, 15, 15, 15));
    }];
    
    
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] init];
    header.userInteractionEnabled = YES;
    [header addGestureRecognizer:tapGesture];
    kWeakSelf;
    [tapGesture.rac_gestureSignal subscribeNext:^(__kindof UIGestureRecognizer * _Nullable x) {
        [weakSelf.mapNavigationView showMapNavigationViewWithtargetLatitude:22.4 targetLongitute:114 toName:@"RuiHe"];
    }];
        
    
    return header;
}

- (UIView *)footBgView{
    
    UIView *footBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH,200)];
    [footBgView setBackgroundColor:UIColor.clearColor];
    
    UIView *view =  [[UIView alloc] initWithFrame:CGRectMake(15, 0, SCREEN_WIDTH-30,200)];
    [view setBackgroundColor:UIColor.whiteColor];
    [view round:5 RectCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight];
    [footBgView addSubview:view];
  
    return footBgView;
}
@end
